﻿package cn.poco.pepsi.service.impl;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import android.util.Log;
import cn.poco.pepsi.bean.Guest;
import cn.poco.pepsi.bean.Restaurant;
import cn.poco.pepsi.service.IGuest;
import cn.poco.pepsi.util.UrlConnectionUtil;
import cn.poco.pepsi.util.UrlMatchUtil;
import cn.poco.pepsi.util.xmlpared.GetResByIdXmlparse;
import cn.poco.pepsi.util.xmlpared.GuestXmlparse;



public class GuestImpl implements IGuest {
	private String TAG="impl";

	@Override
	public List<Guest> getNearGuests(String cd, String lat, String lon, String range, int s, int l)
			throws Exception {
		StringBuilder strBuilder=new StringBuilder();
		strBuilder.append(PATH1).append("?cd="+cd+"&lat="+lat+"&long="+lon+"&range="+range+"&s="+s+"&l="+l);
		String  url=UrlMatchUtil.matchUrl(strBuilder.toString());
		InputStream inputStream= UrlConnectionUtil.getRequest(url);
		Log.i(TAG, url);
		return GuestXmlparse.getXml(inputStream);
	}

	@Override
	public List<Guest> gethotGuests(String cd,String cycle,int l,int s) throws Exception {
		StringBuilder strBuilder=new StringBuilder();
		strBuilder.append(PATH2).append("?cd="+cd+"&cycle="+cycle+"&s="+s+"&l="+l);
		String  url=UrlMatchUtil.matchUrl(strBuilder.toString());
		InputStream inputStream= UrlConnectionUtil.getRequest(url);
		Log.i(TAG, url);
		return GuestXmlparse.getXml(inputStream);
	}

	@Override
	public List<Guest> getmyGuests(String userId, int l,int s) throws Exception {
		StringBuilder strBuilder=new StringBuilder();
		strBuilder.append(PATH3).append("?uid="+userId+"&s="+s+"&l="+l);
		String  url=UrlMatchUtil.matchUrl(strBuilder.toString());
		InputStream inputStream= UrlConnectionUtil.getRequest(url);
		Log.i(TAG, url);
		return GuestXmlparse.getXml(inputStream);
	}

	/**
	 * 根据餐厅ID获取此餐厅对应的食评！
	 */
	@Override
	public ArrayList<Guest> getResCommByResID(String resId, int l, int s) throws Exception {
		StringBuilder strBuilder=new StringBuilder();
		strBuilder.append(IGuest.ResCommByResID).append("?resid="+resId+"&s="+s+"&l="+l);
		String  url=UrlMatchUtil.matchUrl(strBuilder.toString());
		InputStream inputStream= UrlConnectionUtil.getRequest(url);
		Log.i(TAG, url);
		return GuestXmlparse.getXml(inputStream);
	}

	/**
	 * 根据餐厅ID获取餐厅详细信息
	 */
	@Override
	public Restaurant getResDetailsByResID(String resId) throws Exception {
		StringBuilder strBuilder=new StringBuilder();
		strBuilder.append(IGuest.ResDetailsByResID).append("?resid="+resId);
		String  url=UrlMatchUtil.matchUrl(strBuilder.toString());
		InputStream inputStream= UrlConnectionUtil.getRequest(url);
		Log.i(TAG, url);
		return GetResByIdXmlparse.getXml(inputStream);
	}

	
}
